//
//  HLHomeListMatchView.m
//  YueYue
//
//  Created by hulu001 on 2023/5/25.
//

#import "HLHomeListMatchView.h"
#import "HLMatchGoldViewController.h"
#import "HLMatchFateViewController.h"
#import "HLMatchLabelViewController.h"
#import "HLMatchNightTipView.h"
#import "HLMatchNormalViewController.h"

@interface HLHomeListMatchView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation HLHomeListMatchView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColorWhite;
        [self setupView];
        
    }
    return self;
}

- (void)setupView {
    
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 8;
    flowLayout.minimumInteritemSpacing = 0;
    
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    CGFloat scale = 94 / 46.0;
    CGFloat width = (SCREEN_WIDTH - 8 - 32) / 2.0;
    CGFloat height = width / scale;
    
    flowLayout.itemSize = CGSizeMake(width, height);
        //设置代理，实现代理方法
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    _collectionView.pagingEnabled = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.backgroundColor = UIColorWhite;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [_collectionView registerClass:[HLHomeListMatchCell class] forCellWithReuseIdentifier:[HLHomeListMatchCell identifyCell]];
    [self addSubview:_collectionView];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(height);
        make.left.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
    }];
}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.matchs.count;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HLHomeListMatchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[HLHomeListMatchCell identifyCell] forIndexPath:indexPath];
    cell.model = self.matchs[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    HLHomeListMatchModel *model = self.matchs[indexPath.row];
    
    switch (model.cellSpot) {
        case HLHomeListMatchSpotGold:{
            HLMatchGoldViewController *matchVC = [[HLMatchGoldViewController alloc] init];
            [self.qmui_viewController.navigationController pushViewController:matchVC animated:YES];
        }break;
        case HLHomeListMatchSpotFate:{
            HLMatchNormalViewController *matchVC = [[HLMatchNormalViewController alloc] init];
            [self.qmui_viewController.navigationController pushViewController:matchVC animated:YES];
        }break;
        case HLHomeListMatchSpotLabel:{
            HLMatchLabelViewController *matchVC = [[HLMatchLabelViewController alloc] init];
            [self.qmui_viewController.navigationController pushViewController:matchVC animated:YES];
        }break;
        case HLHomeListMatchSpotNight:{
            [HLMatchNightTipView show];
        }break;
    }
}

- (void)setMatchs:(NSArray<HLHomeListMatchModel *> *)matchs
{
    _matchs = matchs;
    [self.collectionView reloadData];
}

@end
